/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_driver.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.MD5Util;
import com.thinkgem.jeesite.common.utils.ToolsUtil;
import com.thinkgem.jeesite.modules.tb_driver.dao.TbDriverDao;
import com.thinkgem.jeesite.modules.tb_driver.entity.TbDriver;

/**
 * 司机管理Service
 * @author ZhangYangZe
 * @version 2017-05-13
 */
@Service
@Transactional(readOnly = true)
public class TbDriverService extends CrudService<TbDriverDao, TbDriver> {

	public TbDriver get(String id) {
		return super.get(id);
	}
	
	public List<TbDriver> findList(TbDriver tbDriver) {
		return super.findList(tbDriver);
	}
	
	public Page<TbDriver> findPage(Page<TbDriver> page, TbDriver tbDriver) {
		return super.findPage(page, tbDriver);
	}
	
	@Transactional(readOnly = false)
	public void save(TbDriver tbDriver) {
		if(!ToolsUtil.isTrue(tbDriver.getDriverPwd())){
			String pwd = tbDriver.getDriverTell().substring(5, 11);
			tbDriver.setDriverPwd(MD5Util.MD5(pwd));
		}else if(ToolsUtil.isTrue(tbDriver.getNewPassword())){
			tbDriver.setDriverPwd(tbDriver.getNewPassword());
		}
		
		super.save(tbDriver);
	}
	
	@Transactional(readOnly = false)
	public void delete(TbDriver tbDriver) {
		super.delete(tbDriver);
	}
	
	@Transactional(readOnly = false)
	public void updateNew(TbDriver tbDriver) {
		dao.updateNew(tbDriver);
	}
	
	/**
	 * 根据司机电话获取信息
	 * @param tell 司机电话
	 * @return
	 */
	public TbDriver fingByTell(String tell){
		return dao.findByUserName(tell);
	}
	
	/**
	 * 根据司机的状态获取司机的列表 
	 * @param TbDriver
	 * @return TbDriver
	 */
	public List<TbDriver> driverTypeOne(TbDriver tbDriver){		
		return dao.driverTypeOne(tbDriver);
	}
}